﻿using MN.Framework.Common;
using MN.Framework.Common.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MN.Framework.UI.Win
{
    public class MnWinView<EntityType> : IBaseView<EntityType> where EntityType : BaseEntity
    {
        Func<ColumnInfo, bool> filter { get; set; }
        public MnWinView(params string[] columns)
            : this(false, columns)  //Func<IColumnInfo, bool> filter
        {

        }
        public MnWinView(bool inverse, params string[] columns)
        {
            if (!inverse)
            {
                var dbColumns = ServiceFactory.GetColumns<EntityType>();
                Columns = new List<ColumnInfo>();
                foreach (var clmn in columns)
                {
                    var Column = dbColumns.SingleOrDefault(c => c.Name == clmn);
                    if (Column != null)
                    {
                        Columns.Add(Column);
                    }
                }
            }
            else
            {
                Columns = ServiceFactory.GetColumns<EntityType>();                
                foreach (var clmn in columns)
                {
                    Columns.RemoveAll(c => c.Name == clmn);
                }
            }
        }
        List<ColumnInfo> Columns
        {
            get;
            set;
        }
        public string ViewName
        {
            get;
            set;
        }
        public List<ColumnInfo> GetColumns()
        {
            return Columns;
        }
        //public void AddColumns()
        //{
        //    Columns = columns;
        //}
    }
}
